/* Exercise 5.26
   ejer5_26.c */
#include <stdio.h>

int isPerfect( int number );

/* function main begins program execution */
int main( void )
{
    int counter;

    for ( counter = 1; counter <= 100000; counter++ )
        if ( isPerfect( counter ))
            printf( "%d\n", counter );
    return 0; /* indicate that program ended successfully */
} /* end function main */

/* Returns 1 if the number is perfect, else returns 0 */
int isPerfect( int number )
{
    int divisorsAccumulator = 0, divisor;

    for ( divisor = 1; divisor < number; divisor++ )
        if ( number % divisor == 0 )
            divisorsAccumulator += divisor;

    if ( number == divisorsAccumulator )
        return 1;
    else
        return 0;
} /* end function isPerfect */
